import type { VbenFormSchema } from '#/adapter/form';
import type { VxeTableGridOptions } from '#/adapter/vxe-table';

import { DICT_TYPE } from '@vben/constants';
import { getDictOptions } from '@vben/hooks';

import { $t } from '#/locales';

/** 表单配置 */
export function useFormSchema(): VbenFormSchema[] {
  return [
    {
      fieldName: 'id',
      component: 'Input',
      dependencies: {
        triggerFields: [''],
        show: () => false,
      },
    },
    {
      fieldName: 'name',
      label: $t('views.mall.promotion.rewardActivity.name'),
      component: 'Input',
      componentProps: {
        placeholder: $t('views.mall.promotion.rewardActivity.namePlaceholder'),
      },
      rules: 'required',
    },
    {
      fieldName: 'startTime',
      label: $t('views.mall.promotion.rewardActivity.startTime'),
      component: 'DatePicker',
      componentProps: {
        placeholder: $t('views.mall.promotion.rewardActivity.startTimePlaceholder'),
        showTime: true,
        valueFormat: 'x',
        format: 'YYYY-MM-DD HH:mm:ss',
      },
      rules: 'required',
    },
    {
      fieldName: 'endTime',
      label: $t('views.mall.promotion.rewardActivity.endTime'),
      component: 'DatePicker',
      componentProps: {
        placeholder: $t('views.mall.promotion.rewardActivity.endTimePlaceholder'),
        showTime: true,
        valueFormat: 'x',
        format: 'YYYY-MM-DD HH:mm:ss',
      },
      rules: 'required',
    },
    {
      fieldName: 'conditionType',
      label: $t('views.mall.promotion.rewardActivity.conditionType'),
      component: 'RadioGroup',
      componentProps: {
        options: getDictOptions(DICT_TYPE.PROMOTION_CONDITION_TYPE, 'number'),
      },
      rules: 'required',
    },
    {
      fieldName: 'productScope',
      label: $t('views.mall.promotion.rewardActivity.productScope'),
      component: 'RadioGroup',
      componentProps: {
        options: getDictOptions(DICT_TYPE.PROMOTION_PRODUCT_SCOPE, 'number'),
      },
      rules: 'required',
    },
    {
      fieldName: 'remark',
      label: $t('common.remark'),
      component: 'Textarea',
      componentProps: {
        placeholder: $t('common.remarkPlaceholder'),
        rows: 4,
      },
    },
  ];
}

/** 列表的搜索表单 */
export function useGridFormSchema(): VbenFormSchema[] {
  return [
    {
      fieldName: 'name',
      label: $t('views.mall.promotion.rewardActivity.name'),
      component: 'Input',
      componentProps: {
        placeholder: $t('views.mall.promotion.rewardActivity.namePlaceholder'),
        allowClear: true,
      },
    },
    {
      fieldName: 'status',
      label: $t('common.status'),
      component: 'Select',
      componentProps: {
        placeholder: $t('common.statusPlaceholder'),
        allowClear: true,
        options: getDictOptions(DICT_TYPE.COMMON_STATUS, 'number'),
      },
    },
    {
      fieldName: 'createTime',
      label: $t('views.mall.promotion.rewardActivity.activityTime'),
      component: 'RangePicker',
      componentProps: {
        placeholder: [$t('views.common.startTime'), $t('views.common.endTime')],
        allowClear: true,
        valueFormat: 'YYYY-MM-DD HH:mm:ss',
      },
    },
  ];
}

/** 列表的字段 */
export function useGridColumns(): VxeTableGridOptions['columns'] {
  return [
    {
      field: 'name',
      title: $t('views.mall.promotion.rewardActivity.name'),
      minWidth: 140,
    },
    {
      field: 'productScope',
      title: $t('views.mall.promotion.rewardActivity.productScope'),
      minWidth: 100,
      cellRender: {
        name: 'CellDict',
        props: { type: DICT_TYPE.PROMOTION_PRODUCT_SCOPE },
      },
    },
    {
      field: 'startTime',
      title: $t('views.mall.promotion.rewardActivity.startTime'),
      minWidth: 180,
      formatter: 'formatDateTime',
    },
    {
      field: 'endTime',
      title: $t('views.mall.promotion.rewardActivity.endTime'),
      minWidth: 180,
      formatter: 'formatDateTime',
    },
    {
      field: 'status',
      title: $t('common.status'),
      minWidth: 100,
      cellRender: {
        name: 'CellDict',
        props: { type: DICT_TYPE.COMMON_STATUS },
      },
    },
    {
      field: 'createTime',
      title: $t('common.createTime'),
      minWidth: 180,
      formatter: 'formatDateTime',
    },
    {
      title: $t('common.action'),
      width: 180,
      fixed: 'right',
      slots: { default: 'actions' },
    },
  ];
}
